<?php
include("FusionChartsFree/Code/PHPClass/Includes/FusionCharts_Gen.php");
?>
<html>
	<head>
		<title>Indicadores Estratégicos</title>
		<link type="text/css" href="css/smoothness/jquery-ui-1.8.14.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
		<script type="text/javascript" src="FusionChartsFree/JSClass/FusionCharts.js"></script>
	</head>

	<body>
<?php
$link = sybase_connect('getbo', 'carga', 'carga2006') or die("Could not connect !");
$db = sybase_select_db('getbo', $link);
$sql = "select distinct
	d.ano_mes,
	d.nm_mes,
	max(case when ds_detalhe_indicador = 'GET' then vl_indicador else null end) as get,
	max(case when ds_detalhe_indicador = 'MOB' then vl_indicador else null end) as mob,
	max(case when ds_detalhe_indicador in ('POS DIAL','POS ETHERNET','POS GPRS FIXO','POS GPRS MÓVEL','POS WIFI') then vl_indicador else null end) as pos,
	max(case when ds_detalhe_indicador = 'TEF' then vl_indicador else null end) as tef,
	max(case when ds_detalhe_indicador not in ('GET','MOB','POS DIAL','POS ETHERNET','POS GPRS FIXO','POS GPRS MÓVEL','POS WIFI','TEF') then vl_indicador else null end) as outros

from dba.indicadores_estrategicos ie, dba.d_data d
where ie.dt_referencia = d.data  and ds_indicador like '%INSTAL)'
group by d.ano_mes, d.nm_mes
order by d.ano_mes";
var_dump($sql);
$rs = sybase_query($sql, $link);
var_dump($rs);
var_dump(sybase_fetch_array($rs));

$FC2 = new FusionCharts("MSLine", "600", "300");
		
$FC2->setSwfPath("FusionChartsFree/Charts/");
		 
$strParam2="xAxisName=Meses;pYAxisName=Base Instalada;sYAxisName=Base Ativa;decimalPrecision=1;";
$FC2->addColors("63B8FF;DAA520;66CDAA;EEEE00");
$FC2->setChartParams($strParam2);

while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addCategory($linha["nm_mes"]);
}	

$rs = sybase_query($sql, $link);
$FC2->addDataset("GET","showValues=1");
while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addChartData($linha["get"]);	
}

$rs = sybase_query($sql, $link);
$FC2->addDataset("MOB","showValues=1");
while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addChartData($linha["mob"]);	
}

$rs = sybase_query($sql, $link);
$FC2->addDataset("POS","showValues=1");
while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addChartData($linha["pos"]);	
}

$rs = sybase_query($sql, $link);
$FC2->addDataset("TEF","showValues=1");
while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addChartData($linha["tef"]);	
}

$rs = sybase_query($sql, $link);
$FC2->addDataset("Outros","showValues=1");
while ($linha = sybase_fetch_assoc($rs)) {
	$FC2->addChartData($linha["outros"]);	
}

$FC2->renderChart();

sybase_close($link);
?>

</body></html>